package com.ita.acmsystem.merchant.service.impl;

import java.util.List;
import java.util.UUID;

import com.ita.acmsystem.merchant.dao.IFoodsDao;
import com.ita.acmsystem.merchant.dao.impl.FoodsDaoImpl;
import com.ita.acmsystem.merchant.entity.Foods;
import com.ita.acmsystem.merchant.service.IFoodService;

public class FoodServiceImpl implements IFoodService {

	private IFoodsDao dao;

	public FoodServiceImpl() {
		super();
		dao = new FoodsDaoImpl();
	}

	public FoodServiceImpl(IFoodsDao dao) {
		super();
		this.dao = dao;
	}

	@Override
	public boolean addFoods(Foods foods) {
		String foodId = foods.getFoodId();
		if (foodId == null || "".equals(foodId)) {
			foods.setFoodId(UUID.randomUUID().toString());
		}
		return dao.persist(foods) != null;
	}

	@Override
	public boolean deleteFoods(String foodId) {
		return dao.delete(foodId);
	}

	@Override
	public boolean updateFoods(Foods foods) {
		return dao.update(foods);
	}

	@Override
	public Foods getFoodsById(String foodsId) {
		return dao.query(foodsId);
	}

	@Override
	public List<Foods> getFoodsByType(String typeId) {
		return dao.queryByType(typeId);
	}

	@Override
	public List<Foods> getFoodsByMerchantId(String merchantId) {
		return dao.queryByMerchantId(merchantId);
	}

	@Override
	public List<Foods> getAllFoods() {
		return dao.queryAll();
	}

	public IFoodsDao getDao() {
		return dao;
	}

	public void setDao(IFoodsDao dao) {
		this.dao = dao;
	}

}
